﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="SaleModiApply_Tf_Edit.aspx.vb" Inherits="Slxt.SaleModiApply_Tf_Edit" %>
<%@ Register TagPrefix="cnt" Namespace="Mysoft.Map.Application.Controls" Assembly="Mysoft.Map.Application.Components" %>
<%@ Register TagPrefix="mnu" Namespace="Mysoft.Map.Application.Menus" Assembly="Mysoft.Map.Application.Components" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>退房变更申请</title>
		<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
				<script language="javascript" src="/_controls/settings.aspx"></script>
		<link rel="stylesheet" type="text/css" href="/_nav/menu.css">
		<link rel="stylesheet" type="text/css" href="/_common/styles/global.css">
		<link rel="stylesheet" type="text/css" href="/_grid/map_grid.css">
		<link rel="stylesheet" type="text/css" href="/_forms/styles/form.css">
		<link rel="stylesheet" type="text/css" href="/_nav/tabs.css">
		<link rel="stylesheet" type="text/css" href="/_nav/nav.css">
		<link rel="stylesheet" type="text/css" href="/_common/styles/select.css">
		<script language="javascript" src="/_controls/setting.js"></script>
		<script language="javascript" src="/_controls/util/util.js"></script>
		<script language="javascript" src="/_controls/datetime/date.js"></script>
		<script language="javascript" src="/_controls/datetime/time.js"></script>
		<script language="javascript" src="/_controls/number/number.js"></script>
		<script language="javascript" src="/_controls/lookup/map_lookup.js"></script>
		<script language="javascript" src="/_controls/lookup/map_lookupDialogs.js"></script>
		<script language="javascript" src="/_nav/menu.js"></script>
		<script language="javascript" src="/_common/scripts/global.js"></script>
		<!-- workflow -->
		<script language="javascript" src="/MyWorkflow/workflow.js"></script>
		<script language="javascript" src="/slxt/js/Public.js"></script>
		<script language="javascript" src="/PubProject/js/Public.js"></script>
		<script language="javascript" src="/slxt/xsxc/XsXc_XsChg.js"></script>		
		<script language="javascript">
		//在线帮助文件
		var _MyHelpfile = "/Slxt/help/topics/交易管理/定单管理/业务变更.html";
		var operHandler="";
		
		// 初始化界面
		function window.onload ()
		{
		     if(__SaleType.value=="合同")
		     {
		        appForm.appForm_CjTotal.parentElement.previousSibling.innerText="合同总价";		     
		     }
			//如果是新增模式,不显示审批信息
				if (appForm.ApproveState.value=="待审批"||appForm.ApproveState.value=="审批中")
				{
					appForm.IsApproved.parentElement.style.display="none";
					appForm.IsApproved.parentElement.previousSibling.style.display="none";					
					
					appForm.Opinion.parentElement.parentElement.style.display="none";				
					
					appForm.ApproveBy.parentElement.parentElement.style.display="none";
														
					appForm.execby.parentElement.parentElement.style.display="none";			
					
				}
				else
				{
				    document.all.Reason.rows=3;
                    document.all.Opinion.rows=3;
                    
				    appForm.ApplyBy.parentElement.parentElement.style.display="none";					
				}
				
				 
                if (appForm.ApplyState.value!="作废")	
                {				
                       appForm.zfreason.parentElement.parentElement.style.display="none";
        								
                       appForm.appForm_zfrName.parentElement.parentElement.style.display="none";
                }
                
                 setRights();     
                    
                document.all.execby.parentElement.parentElement.nextSibling.style.display="none";
                
                document.all.Section1.rows[document.all.Section1.rows.length-1].height="3";
                
                document.all.Section11.rows[document.all.Section11.rows.length-1].height="3";
                
               if(document.all.__isSp&&document.all.__isSp.value=="1" )
				{
				    document.all.Reason.rows=3;
                    document.all.Opinion.rows=3;
				
				   trzc.style.display ="none";
				   trsp.style.display =""; 	
				   appForm.execby.setReadOnly(false);
				   appForm.execdate.setReadOnly(false,false );
				   appForm.execby.setValue(txtUserName.value );
				   appForm.execdate.setValue(txtToday.value);
				   appForm.execby.req="1";
				   appForm.execdate.req="1";
				   appForm.execby.parentElement.previousSibling.className="req";
				   appForm.execdate.parentElement.parentElement.parentElement.parentElement.parentElement.previousSibling.className="req";
				   appForm.execby.parentElement.previousSibling.innerText="经办人";
				   appForm.execdate.parentElement.parentElement.parentElement.parentElement.parentElement.previousSibling.innerText="退房日期";
				     var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","GetPayFromGetin",appForm.appForm_TradeGUID.value,"");
				   if(isNaN(parseFloat(strReturn)))
				   {
				      appForm.Pay.setValue("0");
				   }
				   else
				   {
				     appForm.Pay.setValue(strReturn);
				   }
				   appForm._bSaving=true;
				}
				
				if(document.all.__isRz&&document.all.__isRz.value=="1" )
				{
				    document.all.Reason.rows=3;
                    document.all.Opinion.rows=3;
                    
				   trzc.style.display ="none";
				   trsp.style.display =""; 	
				   appForm.execby.parentElement.previousSibling.innerText="经办人";
				   appForm.execdate.parentElement.parentElement.parentElement.parentElement.parentElement.previousSibling.innerText="退房日期";
				   appForm._bSaving=true;
				   btnOk.style.display ="none" ;
				   btnCancel.innerHTML ="关闭";
				     document.title ="退房变更日志";
				      var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","GetPayFromLog",appForm.oid.value,"");
				   
				   if(isNaN(parseFloat(strReturn)))
				   {
				      appForm.Pay.setValue("0");
				   }
				   else
				   {
				     appForm.Pay.setValue(strReturn);
				   }
				   	appForm._bSaving=true;		
				}
			
            }
			
		
		//审批
		function sp()
		{
		       //先保存申请单
            if (save.syslock=="0" &&appForm.CheckUpdated()) 
            {
                operHandler = "sp";	
                         		
                _unlock();
                save.click();
            }	
            else
            {
               zxsp();
            }               
        }

        //执行审批
        function zxsp()
        {
            operHandler="";
            var strReturn=OpenModalWin("退房审批","/Slxt/XSXC/Order_Sp.aspx?isFrom=sqd","",500,220);

            if(strReturn!=undefined) 
            {
                     strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","SetApplyAudit",appForm.oid.value,strReturn[0],strReturn[1]);
                    if (strReturn=="FAIL" || strReturn==undefined) 
                    {
	                    alert("审批失败，请与管理员联系！");
	                    return false;
                    }
                      window.opener._appGrid_Query(appForm.oid.value);
                   var sUrl="SaleModiApply_Tf_Edit.aspx?mode=3&oid=" + appForm.oid.value +"&SaleGUID=" + escape(appForm.SaleGUID.value) + "&funcid=" + escape(__funcid.value)+ "&SaleType=" + escape(__SaleType.value);
                    appForm._bSaving=true;
                    self.navigate(sUrl);
                   
            }                 
		}
		
			//发起审批
		function doNewProcess()
		{
		    //先保存申请单
            if (save.syslock=="0" &&appForm.CheckUpdated()) 
            {
                operHandler = "fqsp";	
                         		
                _unlock();
                save.click();
            }	
            else
            {
                //注：需要传入真实的 房间信息 和 变更日期
                StartupNewApproveProcess(appForm.oid.value,'退房审批',document.all.Section1.rows[1].cells[1].firstChild.innerText,appForm.ApplyDate.value);
            }
        }

        //功能：打开审批流程窗口
		function doOpenProcess()
		{			  
            ApproveProcess(appForm.oid.value);
		}
		
		//工作流处理后
		function afterWorkflow(strProcessGUID)
		{
		    window.opener._appGrid_Query(appForm.oid.value);		// 刷新并定位网格id="appGrid"
	         //window.location.reload();
	        var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","GetApplyState",appForm.oid.value,""); 
	         if(strReturn=="已审批"||strReturn=="审批中")
	        {
	           window.navigate( document.URL.replace("mode=2","mode=3"));
	        }
	        else
	        {
	           //判断工作流中是否已经发起审批
			   strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","VerifyTradeIsFqSp",appForm.oid.value,"");
			   if(strReturn!="PASS")
			   {
			      window.navigate( document.URL.replace("mode=2","mode=3"));
			   }
			   else
			   {
	             window.navigate(  document.URL.replace("mode=3","mode=2"));	
	           }	        
	        }
		}
		
			
					
		//保存数据
		function Save()
		{
			if (CheckApplyType()!=false)	appForm.Save();
			
		}		
		
		//保存并关闭
		function SaveAndClose()
		{
			if (CheckApplyType()!=false) appForm.SaveAndClose();			
		}
		
		
		//校验:同一个销售单不能同时存在两个或两个以上的同类型变更申请
		function CheckApplyType()
		{
			var strReturn = GetDataFromXMLHTTP("/SLXT/XSXC/XSXC_XMLHTTP.aspx","CheckApplyType",appForm.oid.value,appForm.ApplyType.value+"|"+appForm.SaleGUID.value);
			if (strReturn=="NOPASS") 
			{
				alert("该变更申请已存在，请修改！");
				return false;
			}
		}
		
		//打开客户链接
		function OpenSaleModiApplyCustomer(CstGUID)
		{
			event.returnValue=false;
			if(document.all.__showmodel&&document.all.__showmodel.value=="0")
			{
		    	parent.dialogArguments.OpenCustomer("3",CstGUID,"01010203");
			 return;
			 }
			OpenCustomer("3",CstGUID,"01010203");
		}
		
		//打开房间链接
		function OpenSaleModiApplyRoom(RoomGUID)
		{	
			event.returnValue=false;
			if(document.all.__showmodel&&document.all.__showmodel.value=="0")
			{
			   parent.dialogArguments.OpenRoomList("3",RoomGUID,'01010105');
			   return;
			}
			
			OpenRoomList("3",RoomGUID,'01010105');
		}

		//打开定单合同查询窗口
		function OpenOrderContract(sSaleGUID)
		{
			event.returnValue=false;
			
			var sSaleTyep=appForm.SaleType.value;
			if (sSaleTyep=="定单") sSaleTyep='小订';
			if(document.all.__showmodel&&document.all.__showmodel.value=="0") 
			{
			   parent.dialogArguments.openModiOrderContractWin(appForm.ProjGUID.value,sSaleGUID,sSaleTyep,3);
			   return;
			}
			openModiOrderContractWin(appForm.ProjGUID.value,sSaleGUID,sSaleTyep,3)
		}
			
		function oprBeforeSave()
		{
			// 例：appForm.userxml = "<myxml>我定义的xml</myxml>"
			//alert(appForm.dataxml);
			event.returnValue = true;
		}
		
		 function Ok()
		 {
		    
		    if(Trim(appForm.execby.value) == "")
			{
				alert("请录入经办人！");
				appForm.execby.focus();
				return;
			}
			if(appForm.execdate.value == "")
			{
				alert("请选择退房日期！");
				appForm.execdate.focus();
				return;
			}	
			// 例：appForm.userxml = "<myxml>我定义的xml</myxml>"
			var strDataXml="";
		
		    strDataXml="<s_SaleModiLog keyname=\"SaleModiLogGUID\" keyvalue=\"\">";
            strDataXml+="<BUGUID>" +appForm.BUGUID.value +"</BUGUID>" ;
            strDataXml+="<ProjGUID>" +appForm.ProjGUID.value +"</ProjGUID>";
            strDataXml+="<ForeSaleGUID>" +appForm.SaleGUID.value +"</ForeSaleGUID>";
            strDataXml+="<ForeSaleType>" +appForm.SaleType.value +"</ForeSaleType>";
            strDataXml+="<ApplyType>" +appForm.ApplyType.value +"</ApplyType>";
            strDataXml+="<PastObligee>" +appForm.CstName.value +"</PastObligee>";
            strDataXml+="<PastObligeeGUID>" +appForm.CstGUID.value +"</PastObligeeGUID>";
            strDataXml+="<PastRoomGUID>" +appForm.RoomGUID.value +"</PastRoomGUID>";
            strDataXml+="<NowObligee></NowObligee>";
            strDataXml+="<NowObligeeGUID></NowObligeeGUID>";
            strDataXml+="<NowRoomGUID></NowRoomGUID>" ;
            strDataXml+="<BackSaleGUID></BackSaleGUID>" ;
            strDataXml+="<BackSaleType></BackSaleType>";
            strDataXml+="<ForeTradeGUID>" +appForm.appForm_TradeGUID.value +"</ForeTradeGUID>" ;
            strDataXml+="<Pay>" +appForm.Pay.value.replace(/,/ig,"") +"</Pay>";
            strDataXml+="<Refundment>0</Refundment>" ;
            strDataXml+="<ReasonSort>" +appForm.ReasonSort.value +"</ReasonSort>";
            strDataXml+="<Reason>" +appForm.Reason.value +"</Reason>" ;
            strDataXml+="<HandCharge>" +appForm.HandCharge.value.replace(/,/ig,"") +"</HandCharge>" ;
            strDataXml+="<ApproveBy>" +appForm.ApproveBy.value +"</ApproveBy>" ;
            strDataXml+="<ApproveDate>" +appForm.ApproveDate.value +"</ApproveDate>" ;
            strDataXml+="<ApplyBy>" +appForm.execby.value +"</ApplyBy>" ;
            strDataXml+="<ApplyDate>" +appForm.execdate.value +"</ApplyDate>";
            strDataXml+="</s_SaleModiLog>";	
            
			parent.returnValue=strDataXml;
			event.returnValue = false;
			appForm._bSaving=true;
			appForm._bAlert=false;
			parent.window.close();
		 }
		 
		 function oprAfterSave()
		    {
		  	    var xmlDom = new ActiveXObject("Microsoft.XMLDOM")
	            try
	            {
		            xmlDom.loadXML(appForm.returnxml);
	            }
	            catch(e)
	            {
		            alert("返回的xml格式错误，请与管理员联系！");
		            operHandler="";
		            return;
	            } 
	            
	             if(operHandler == "fqsp")
	            {
	                operHandler="";
	                //注：需要传入真实的 房间信息 和 变更日期
                    StartupNewApproveProcess(appForm.oid.value,'退房审批',document.all.Section1.rows[1].cells[1].firstChild.innerText,appForm.ApplyDate.value);
	            }
    	        
	             if(operHandler == "sp")
	            {
	                zxsp();
	            }   
    	       
	             try
	            {
	              if(__mode.value=="1")
	              {
	                parent.opener.parent.window.refreshMe();
	                 
	                parent.opener.window.ShowHideMenu();
	              }
	            }
	            catch (e)
	            {
    	        
	            } 
		        event.returnValue = true;
		    }
		</script>
	</HEAD>
	<body MS_POSITIONING="GridLayout">
		<table class="layout" cellSpacing="0" cellPadding="0">
			<COLGROUP>
				<col width="140"> <!-- 导航菜单：140px -->
				<col>
			</COLGROUP>
		<tr height="48" id="trzc">
				<td colSpan="2">
					<input id="txtUserName" type="text" style="DISPLAY:none" runat="server"> <input id="txtToday" type="text" style="DISPLAY:none" runat="server">
					<!-- 菜单 --><mnu:appformmenu id="appFormMenu" runat="server"></mnu:appformmenu></td>
			</tr>
			<tr>
				<td colSpan="2">
					<div class="area">
						<cnt:AppForm id="appForm" runat="server" DefaultValueXml="" processtype="xmlhttp" assembly="Mysoft.Map.Core" invokeclass="Mysoft.Map.Data.MyDB" invokefunction="SaveXml" onbeforesave="oprBeforeSave()"   onaftersave="oprAfterSave()"></cnt:AppForm>
					</div>
				</td>
			</tr>
		<tr height="40"  id="trsp"  style="display:none">
					<td class="buttons" colSpan="2">
						<button onclick="Ok()" id="btnOk" type="button">确 定</button>&nbsp;&nbsp; <button onclick="parent.window.close();"  id="btnCancel"  type="button">
							取 消</button>
					</td>
				</tr>
		</table>
			<form id="Form1" runat="server">
			<input id="txtWorkFlowGuid" type="text" style="DISPLAY:none">
			<!-- 业务参数  -->
			<asp:textbox id="txtBgShConfig" style="DISPLAY: none" Runat="server"></asp:textbox><!--变更审批业务参数设置值-->
			</form>
	</body>
</HTML>
